package com.shishuo.cms.dao;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import com.shishuo.cms.entity.vo.FolderVo;

@Repository
public class RedisDaoTemplate<T> {
	private static final Class T = null;
	@Autowired
	private RedisTemplate<String, T> redisTemplate;

	public void setRedisTemplate(RedisTemplate<String, T> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	public T getValue(String keyStr) {
		return (T) redisTemplate.opsForValue().get(keyStr);
	}

	public void setValue(T t, String keyStr) {
		redisTemplate.opsForValue().set(keyStr, t);
	}

	public void hashPut(String ObjectKey, String keyStr, Object object) {
		redisTemplate.opsForHash().put(ObjectKey, keyStr, object);
	}

	public void hashDelete(T key, String ObjectKey, String keyStr) {
		redisTemplate.opsForHash().delete(ObjectKey, keyStr);
	}

	public Object hashGet(String ObjectKey, String keyStr) {
		if (redisTemplate.hasKey(ObjectKey))
			return redisTemplate.opsForHash().get(ObjectKey, keyStr);
		else {
			return null;
		}
	}

	public Map<Object, Object> hashGetAll(String ObjectKey) {
		if (redisTemplate.hasKey(ObjectKey)) {
			return redisTemplate.opsForHash().entries(ObjectKey);
		} else
			return null;
	}

}
